from typing import List

from afast_core.core_libs.zyxorm.utils import md5
from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends, Path, Body

from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.department.services import DepartmentBusinesses




class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''

    department_id: int = Body(None, alias='departmentId', title="departmentId", description='department_id')
    manager_id: int = Body(None, alias='managerId', title="managerId", description='manager_id')
    department_code: str = Body(None, alias='departmentCode', title="departmentId", description='department_id')
    name: str = Body(None, alias='name', title="name", description='name')
    parent_id: int = Body(0, alias='parentId', title="parent_id", description='parent_id')
    sort: int = Body(0, alias='sort', title="sort", description='sort')
    create_time: str = Body('now()', alias='creat_time', title="creat_time", description='loginName')
    update_time: str = Body('now()', alias='updateTime', title="updateTime", description='loginName')


class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 schema_param: XParam,
                 ):
        super().__init__(request=request)
        # 入参参数
        # 入参参数
        self.schema_param = schema_param


@RestControllerWithDepends()
class SystemDepartmentAddController(IController):

    def business_login(self):
        pass

        # 先判断名称是否重复
        if DepartmentBusinesses.get_sys_dpartment_info_by_name(name=self.schema_param.name):
            self.response_api_code = 30001
            self.response_ok = False
            self.response_msg = '部门名称已存在，请重新输入！'
            return

        if self.schema_param.department_id ==0:
            self.schema_param.department_id = DepartmentBusinesses.get_sys_dpartment_id_max_id() + 1
        result = DepartmentBusinesses.add_sys_dpartment_info(
            **self.schema_param.dict()
        )
        if result:
            self.response_msg = '添加成功'
        else:
            self.response_ok = False
            self.response_msg = '添加失败'
            return None
        return None
